<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title>Contra</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="../js/enchant.min.js"></script>
        <script type="text/javascript" src="../js/plugins/tl.enchant.js"></script>
        <script type="text/javascript">
            //Game Init
            enchant();
            var game
            var scene;
            var player1;
            var map;
            window.onload = function(){  
                game = new Core(500,500);
                game.preload('../images/contra/bg.png','../images/contra/player.png','../images/contra/contras_intro4.gif','../images/contra/ContraSheet3.gif','../images/contra/Contra-Stage1.png','../images/contra/selector.jpg');                   
                game.onload = function(){
                    //Init
                    scene = new Scene();
                    var background_intro1 = new Sprite(300,225);
                    background_intro1.image = game.assets['../images/contra/contras_intro4.gif'];
                    var player_select = new Sprite(19,11);
                    player_select.image = game.assets['../images/contra/selector.jpg'];
                    player_select.x = 105;
                    player_select.y = 150;
                    scene.addChild(background_intro1);
                    scene.addChild(player_select);
                    game.rootScene.addChild(scene);  
                    
                    //Key binding
                    game.keybind('2'.charCodeAt(0),'a');
                    game.keybind('1'.charCodeAt(0),'b');
                    game.keybind(32, "space");
                    
                    game.keybind('W'.charCodeAt(0),'a');
                    game.keybind('S'.charCodeAt(0),'a');
                    game.keybind('A'.charCodeAt(0),'b');
                    game.keybind('D'.charCodeAt(0),'b');
                        
                    var start_stage1 = function(){
                        scene.removeChild(background_intro1)
                        scene.removeChild(player_select)
                        player1 = new Sprite(30,40);
                        player1.image = game.assets['../images/contra/player.png'];                                                              
                                                                                                                                            
                        var map = new Map(32, 32);
                        map.image = game.assets['../images/contra/bg.png'];
                        
                        var map1 = [
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1],
                            [  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],                            
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                        ];
                        
                        var colMap = [
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                            [  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1],
                            [  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],                               
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                            [  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
                        ];
                        map.collisionData = colMap;
                       
                        
                        map.loadData(map1);
                        player1.addEventListener("enterframe",function(){
                            this.frame = [2,2,3,3];
                            this.tl.moveBy(30, 250, 90).removeFromScene();
                            
                        })
                                                
                        scene.addChild(map);
                        scene.addChild(player1);
                    };   
                    
                    var key_up = function(e) {
                        console.log(e.type)
                        player_select.y = 150;
                    };
                    var key_down = function(e) {
                        console.log(e.type)
                        player_select.y = 150 + 10;
                    };
                    
                    game.addEventListener("abuttondown",key_down);
                    game.addEventListener('bbuttondown',key_up);
                    game.addEventListener("spacebuttondown", start_stage1);                                                                                              
                }
                
                
                game.start();                
            }
            
            
        </script>
    </head>
    <body>       
    </body>
</html>
